﻿using UnityEngine;
using System.Collections;

public class Asteroid : MonoBehaviour , ITakeDamage
{
    public GameObject DestroyEffect;
    public float pointsScaleFactor;

    public void OnTriggerEnter2D(Collider2D other)
    {
        var player = other.GetComponent<Player>();

        if (player == null)
            return;

        LevelManager.Instance.KillPlayer();        
    }

    public void TakeDamage(int Damage, GameObject instigator)
    {
        if (DestroyEffect != null)
            Instantiate(DestroyEffect, transform.position, transform.rotation);

        var projectile = instigator.GetComponent<Projectile>();
        if (projectile != null && projectile.Owner.GetComponent<Player>() != null)
        {
            GameManager.Instance.AddPoints((int)(gameObject.transform.localScale.x * pointsScaleFactor));
            LevelManager.Instance.asteroidDestroyed(gameObject);
            Destroy(gameObject);
        }
    }

}
